package main;


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;


public class Reader {
	
	private HashMap<String, Word> words;

	public HashMap<String, Word> readTraining(){
		words = new HashMap<String,Word>();
		Integer ad = 0;
		
		try{
			FileInputStream fis = new FileInputStream("in.txt");
			DataInputStream ds = new DataInputStream(fis);
			BufferedReader br = new BufferedReader(new InputStreamReader(ds));
			
			String line = "";
			
			
			
	
			
			
			while((line = br.readLine()) != null){
				String[] tabs = line.split("\\t");
				
					if(tabs.length == 6 && !tabs[2].equals(tabs[4])){
					
						if(words.containsKey(tabs[2])){
							Word temp = words.get(tabs[2]);
							temp.incrementCount();
							if(tabs[4].equals(tabs[5])){
								temp.incrementType(tabs[4]);
							}else{
								temp.incrementType(tabs[4]);
								//temp.incrementType(tabs[5]);
							}
						}else{
							Word temp = new Word(tabs[2]);
							if(tabs[4].equals(tabs[5])){
								temp.incrementType(tabs[4]);
							}else{
								temp.incrementType(tabs[4]);
								//temp.incrementType(tabs[5]);
							}
							words.put(tabs[2], temp);
						}
						
						
						
					}
					
				
			}
			
					
			
		}catch(IOException e){
		
		}
		
		/*System.out.println( words.get("stage").getCount());
		System.out.println( words.get("stage").getTypeOc());
		System.out.println( words.get("stage").mostFrequent());*/
		return words;
		
	}

	public ArrayList<String> readDevelopment() {
		ArrayList<String> dWords = new ArrayList<String>();
		try{
			FileInputStream fis = new FileInputStream("ind.txt");
			DataInputStream ds = new DataInputStream(fis);
			BufferedReader br = new BufferedReader(new InputStreamReader(ds));
			
			String line = "";
			while((line = br.readLine()) != null){
				//System.out.println(line);
				String[] tabs = line.split("\\t");
				
				if(tabs.length == 6 ){
					if(!tabs[2].equals(tabs[4])){
						dWords.add(tabs[2]);
					}
				}
			}
			
			
		}catch(IOException e){
			
		}
		return dWords;
	}		
	
}
